package edu.depaul.se.courseregistration.jpa.courses;

import edu.depaul.se.courseregistration.jpa.schedule.Schedule;
import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@Table(name = "COURSE_SECTION")
@NamedQueries({
    @NamedQuery(name = Section.SECTION_QUERY_ALL, query = "select s from Section s"),
    @NamedQuery(name = Section.SECTION_QUERY_BY_COURSE_ID, query = "SELECT s FROM Section s WHERE s.courseNumber = :" + Section.COURSE_ID_PARAMETER_NAME),
    @NamedQuery(name = Section.SECTION_QUERY_BY_IS_OPEN, query = "SELECT s FROM Section s WHERE s.isOpen  = :" + Section.SECTION_IS_OPEN_PARAMETER_NAME),
    @NamedQuery(name = Section.SECTION_QUERY_BY_ID, query = "SELECT s FROM Section s WHERE s.sectionId = :" + Section.SECTION_ID_PARAMETER_NAME) //Find Course By ID.
})
/**
 *
 * @author lmarco
 */
public class Section implements Serializable {

    private static final long serialVersionUID = 1L;
    public static final String SECTION_QUERY_ALL = "Section.findAll";
    public static final String SECTION_QUERY_BY_COURSE_ID = "Section.findByCourse";
    public static final String SECTION_QUERY_BY_IS_OPEN = "Section.findByOpen";
    public static final String SECTION_QUERY_BY_ID = "section.findBySectionId";
    public static final String COURSE_ID_PARAMETER_NAME = "courseNumber";
    public static final String SECTION_ID_PARAMETER_NAME = "sectionId";
    public static final String SECTION_IS_OPEN_PARAMETER_NAME = "isOpen";
    @Id
    @Column(name = "SECTION_ID")
    private Integer sectionId;
    @JoinColumn(name = "COURSE_ID", referencedColumnName = "COURSE_ID")
    @ManyToOne(optional = false)
    private Course courseNumber;
    @OneToOne(cascade = CascadeType.ALL)
    private Schedule personID;

    public Schedule getPersonID() {
        return personID;
    }

    public void setPersonID(Schedule personID) {
        this.personID = personID;
    }

    @XmlTransient
    public Course getCourseNumber() {
        return courseNumber;
    }

    public void setCourseNumber(Course courseNumber) {
        this.courseNumber = courseNumber;
    }

    @Column(name = "IS_OPEN")
    private boolean isOpen;
    @Column(name = "INSTRUCTOR_NAME")
    private String instructorName;
    @Column(name = "SECTION_DATES")
    private String sectionDates;
    @Column(name = "MEETING_HOURS")
    private String meetingHours;
    @Column(name = "BUILDING_NAME")
    private String buildingName;
    @Column(name = "ROOM_NUMBER")
    private String roomNumber;
    @Column(name = "SECTION_PRICE")
    private Integer sectionPrice;

    public Integer getSectionPrice() {
        return sectionPrice;
    }

    public void setSectionPrice(Integer sectionPrice) {
        this.sectionPrice = sectionPrice;
    }

    public int getSectionID() {
        return sectionId;
    }

    public void setSectionID(int sectionID) {
        this.sectionId = sectionID;
    }

    public boolean getSectionStaus() {
        return isOpen;
    }

    public void setSectionStaus(boolean isOpen) {
        this.isOpen = isOpen;
    }

    public String getInstructorName() {
        return instructorName;
    }

    public void setInstructorName(String instructorName) {
        this.instructorName = instructorName;
    }

    public String getSectionDates() {
        return sectionDates;
    }

    public void setectionDates(String sectionDates) {
        this.sectionDates = sectionDates;
    }

    public String getMeetingHours() {
        return meetingHours;
    }

    public void setMeetingHours(String meetingHours) {
        this.meetingHours = meetingHours;
    }

    public String getBuildingName() {
        return buildingName;
    }

    public void setBuildingName(String buildingName) {
        this.buildingName = buildingName;
    }

    public String getRoomNumber() {
        return roomNumber;
    }

    public void setRoomNumber(String roomNumber) {
        this.roomNumber = roomNumber;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (sectionId != null ? sectionId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Section)) {
            return false;
        }
        Section other = (Section) object;
        if ((this.sectionId == null && other.sectionId != null) || (this.sectionId != null && !this.sectionId.equals(other.sectionId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("\n=================SECTION INFO===============\n\t sectionId: ").append(this.sectionId);
        sb.append(",\n\t courseInfo: ").append(this.courseNumber);
        sb.append(",\n\t isOpen: ").append(this.isOpen);
        sb.append(",\n\t instructor name: ").append(this.instructorName);
        sb.append(",\n\t meeting hours: ").append(this.meetingHours);
        sb.append(",\n\t building name: ").append(this.buildingName);
        sb.append(",\n\t room number: ").append(this.roomNumber);
        sb.append("\n=============================================");

        return sb.toString();
    }
}
